// pages/my/my.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bgsrc: '',
    headicon: '../../images/moren.png',
    nickname: '请登录',
    // myurl: '../index/index',
    dayu:'../../images/dayuhao.png',
    fulllists:[
      {id:1,src: '../../images/daifukuan.png', text: '待付款' },
      {id:2,src: '../../images/daiwancheng.png', text: '待完成' },
      {id:4,src: '../../images/yiwancheng.png', text: '已完成' },
      {id:3,src: '../../images/daipingjia.png', text: '待评价' },
    ],
    modulelists:[
      { url: '../myorder/order', src: '../../images/wodeyuyue.png', text: '我的预约' },
      { url: '../myYouhui/myYouhui?id=1', src: '../../images/wodeyouhuiquan.png', text: '我的优惠券' },
      { url: '../jifen/jifen', src: '../../images/wodejifen.png', text: '我的积分' },
      { url: '', src: '../../images/wodedizhi.png', text: '我的地址' },
    ],
    disabled:false,
  },
  login(userinfo) { 
    var that=this;
    app.login(userinfo, (err, res) => { 
      if (err){ return console.log('login function has error')}
      else{
        that.setData({
          nickname: userinfo.detail.userInfo.nickName,
          headicon: userinfo.detail.userInfo.avatarUrl,
          bgsrc: userinfo.detail.userInfo.avatarUrl,
          disabled: true
        })
      } 
    })
  },
  navgoto:function(e){
    if (e.currentTarget.dataset.url==''){
      var that = this;
      wx.chooseAddress({
        success: function (res) {
        },
        fail: function (res) {
          wx.getSetting({
            success(res) {
              if (!res.authSetting['scope.address']) {
                wx.authorize({
                  scope: 'scope.address',
                  success(res) {
                  },
                  fail: function (res) {
                    wx.openSetting({
                      success: (res) => {
                        if (!res.authSetting["scope.address"]) {
                          wx.showModal({
                            title: '提示',
                            content: '通讯地址授权失败，不能使用外卖',
                            showCancel: false,
                            success: function (res) {
                            }
                          })
                        }
                      }
                    })
                  }
                })
              }
            }
          })
        }
      })
      return false;
    }
    wx.navigateTo({
      url:e.currentTarget.dataset.url,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    if (app.globalData.user.nickname){
      that.setData({
        nickname: app.globalData.user.nickname,
        headicon: app.globalData.user.avatar_url,
        bgsrc: app.globalData.user.avatar_url,
        disabled:true
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})